/*
 * Copyright 2012-2014 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.jqd.framework.core.persistence;

import java.io.Serializable;

import com.jqd.framework.core.exception.DAOException;

/**
 * 
 * 持久化层API
 * 
 * @author liaozhicheng.cn@gmail.com
 * @date 2012-6-11
 * @since 1.0
 */
public interface BaseRepository {
	
	/**
	 * 保存实体的方法
	 * 
	 * @param entity
	 *            实体类对象
	 */
	void saveEntity(Object entity) throws DAOException;
	
	
	/**
	 * 删除实体类，直接通过对象方式删除
	 * 
	 * @param entity
	 * @throws DAOException
	 */
	void deleteEntity(Object entity) throws DAOException;
	
	
	/**
	 * 一次删除多个实体类对象
	 * 
	 * @param <T>
	 * @param entityClazz
	 *            实体类类型
	 * @param primaryKeys
	 *            主键数组
	 */
	<T> void deleteEntity(Class<T> entityClazz, Serializable... primaryKeys) throws DAOException;
	
	
	/**
	 * 更新实体对象
	 * 
	 * @param entity
	 *            实体类对象
	 */
	void updateEntity(Object entity) throws DAOException;
	
	
	/**
	 * 获取对象的引用，返回的是一个代理对象，注意：load 与 find 的区别
	 * 
	 * @param entityClazz
	 *            实体类型
	 * @param primaryKey
	 *            主键
	 * @return
	 * @throws DAOException
	 */
	<T> T loadEntity(Class<T> entityClazz, Serializable primaryKey) throws DAOException;
	
	
	/**
	 * 查找实体类对象
	 * 
	 * @param <T>
	 *            泛型
	 * @param entityClazz
	 *            实体类类型
	 * @param primaryKey
	 *            主键
	 * @return 实体类对象
	 */
	<T> T findEntity(Class<T> entityClazz, Serializable primaryKey) throws DAOException;
	
}
